package com.huluobo.high3videoproject.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

public class GlideUtils {

    /**
     * 加载圆角图片
     *
     * @param context      上下文
     * @param imageView    控件
     * @param url          地址
     * @param defaultImage 默认图片
     * @param errorImage   错误图片
     * @param radius       圆角
     */
    public static void load(Context context, ImageView imageView, String url, int defaultImage, int errorImage,
                            int radius) {
        RequestOptions requestOptions = new RequestOptions()
                .priority(Priority.NORMAL)//加载优先级
                .placeholder(defaultImage)//默认图片
                .error(errorImage)//错误图片
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)//是否加载原始数据
                .centerCrop()
                .transform(new RoundedCorners(radius));

        Glide.with(context).load(url).apply(requestOptions).into(imageView);
    }

    public static void loadRound(Context context, ImageView imageView, String url) {
        RequestOptions requestOptions = RequestOptions.centerCropTransform();//直接加载圆角图片
        Glide.with(context).load(url).apply(requestOptions).into(imageView);
    }

    public static void loadNormal(Context context, ImageView imageView, String url) {
        Glide.with(context).load(url).into(imageView);
    }
}
